home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 49
/
Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso
/
-serious-
/
misc
/
football
/
exec
/
cupscheduler.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-11-29
|
13KB
|
497 lines
/* ***********************************************************************
CUP SCHEDULER PROGRAM FOR FOOTBALL REXX SUITE
-----------------------------------------------
Copyright Mark Naughton 1997
Version Date History
--------------------------------------------------------------------------
1.0 121097 Wrote the random match generator.
201097 Wrote the main routine that creates all the files,
such as sorting the 'cf' file, creating the
working/history files and randomly generating a
schedule. This program will ONLY create the files and
not maintain them. That is left to
"CupScheduleNextRound.rexx".
221097 Tidied report and added number of matches to be
played. If a history file is found but it is switched
off then it will not be deleted.
311097 Changed format of 'working' file - added CRDN.
091297 Cup history file creation has been dummied out for
the time being.
151297 Tidied display and removed CupHistory code.
060698 Added code for manual scheduling.
260898 Added code for handling 2 legs.
050998 Didn't read setting for away goals.
250899 Added error msg for file check.
290899 Converted to use locale. Some error messages, before
reading the locale, will still be in English.
030999 Moved global Cup variables into a different file.
040999 Report shows better words for the settings for the
rounds - Have decided to keep the datafile settings in
English for easier controls - looks better though....
**************************************************************************
Procedure
---------
1. Check files exist.
2. Read '.cf' and write teams to output file.
3. Using external program, sort the teams.
4. Re-read the teams and recreate '.cf'.
5. Open '.cf' for reading.
6. Extract data and store.
7. If no separator in it, then take it as a
team. Strip blanks and store.
8. Close input file.
9. Create '.cfrw' working file with round/teams.
10.Randomly generate who is going to play who and store in array but only
if the matches are to be automatically scheduled.
11.Create '.scf' file and using the order in which the numbers were
generated earlier, write the particular teams.
12.Write report and exit.
************************************************************************** */
PARSE ARG league_stuff
version = 1
input_file = '.cf'
input2_file = '.scf'
input3_file = '.cfrw'
input4_file = '.cfh'
output3_file = '.temp'
title = '*CUP_TITLE='
thirdpl = '*CUP_THIRD='
rounddef = '*CUP_RNDDEF='
cuphistory = '*CUP_HISTORY='
schedtype = '*CUP_SCHEDULE='
awaygs = '*CUP_AWAYG='
pkversion = '* Version='
matches. = '???'
separator = '*'
teams. = '???'
rnds. = '???'
tcount = 0
ttc = 0
rndcnt = 0
league_file = "Data/"league_stuff
if open(datafile,"Data/Football.locale",'r') then do
line = readln(datafile)
locdir = strip(line)
close(datafile)
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot read 'Data/Football.locale' for the locale settings."
exit
end
dcupdir = locdir"Football.locale_cup"
locdir = locdir"Exec/CupScheduler.data"
if open(datafile,"ENV:FootballRXPath",'r') then do
line = readln(datafile)
rxdir = strip(line)
close(datafile)
end
else
rxdir = "SYS:Rexxc/"
if exists(locdir) > 0 then do
address command rxdir'rx 'locdir
VarCount = getclip('VarCount')
do i = 1 to VarCount
interpret getclip('var.'i)
end
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot find '"locdir"' to read locale settings."
exit
end
if exists(dcupdir) > 0 then do
address command rxdir'rx 'dcupdir
VarCount = getclip('VarCount')
do i = 1 to VarCount
interpret getclip('var.'i)
end
end
else do
say
say "ERROR : (CupScheduler)"
say
say "Cannot find '"dcupdir"' to read cup locale settings."
exit
end
if exists(league_file || input_file) = 0 then do
say
say cs_error
say
say cs_t1"'"league_file||input_file"'."
exit
end
ttc = 0
tcount = 0
if open(datafile,league_file || input_file,'r') then do
if open(datafile2,league_file || output3_file,'w') then do
do while ~eof(datafile)
line = readln(datafile)
line = strip(line)
if pos(separator,line) > 0 then do
tcount = tcount + 1
teams.tcount = line
end
else do
ttc = ttc + 1
writeln(datafile2,line)
end
end
close(datafile2)
end
else do
say
say cs_error
say
say cs_t2"'"league_file||output3_file"'."
close(datafile)
exit
end
close(datafile)
end
else do
say
say cs_error
say
say cs_t3"'"league_file || input_file"'"cs_t4
exit
end
address command 'sort 'league_file || output3_file league_file || output3_file
if open(datafile2,league_file || output3_file,'r') then do
if open(datafile,league_file || input_file,'w') then do
do i=1 to tcount
writeln(datafile,teams.i)
end
do j=1 to ttc /* while ~eof(datafile2) */
line = readln(datafile2)
line = strip(line)
if j = ttc then
writech(datafile,line)
else
writeln(datafile,line)
end
close(datafile)
end
else do
say
say cs_error
say
say cs_t2"'"league_file||input_file"'."
close(datafile2)
exit
end
close(datafile2)
end
else do
say
say cs_error
say
say cs_"'"league_file||output3_file"'."
close(datafile)
exit
end
address command 'delete >NIL: 'league_file || output3_file
tcount = 0
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(title,line) > 0 then cupname = delstr(line,1,11)
if pos(thirdpl,line) > 0 then third = delstr(line,1,11)
if pos(awaygs,line) > 0 then awaygoals= delstr(line,1,11)
if pos(pkversion,line) > 0 then fversion = delstr(line,1,12)
if pos(cuphistory,line) > 0 then cuph = delstr(line,1,13)
if pos(schedtype,line) > 0 then scht = delstr(line,1,14)
if pos(rounddef,line) > 0 then do
rndcnt = rndcnt + 1
rnds.rndcnt = delstr(line,1,12)
end
if pos(separator,line) = 0 then do
line = strip(line)
tcount = tcount + 1
teams.tcount = line
end
end
close(datafile)
end
else do
say
say cs_error
say
say cs_t3"'"league_file || input_file"'."
exit
end
if open(datafile2,league_file || input3_file,'w') then do
writeln(datafile2,"*")
writeln(datafile2,"* WORKING CUP FILE")
writeln(datafile2,"*")
writeln(datafile2,"*CUP_TITLE="cupname)
writeln(datafile2,"*CUP_ROND=1")
if pos("2 Legs",rnds.1) > 0 then
writeln(datafile2,"*CUP_CRDN="left(rnds.1,6)" 1 Leg")
else
writeln(datafile2,"*CUP_CRDN="left(rnds.1,6))
writeln(datafile2,"*CUP_RDEF="rnds.1)
writeln(datafile2,"*CUP_TCNT="tcount)
writeln(datafile2,"*")
do i=1 to tcount
if i = tcount then
writech(datafile2,teams.i)
else
writeln(datafile2,teams.i)
end
close(datafile2)
end
else do
say
say cs_error
say
say cs_t2"'"league_file || input3_file"'."
exit
end
/* Schedule matches */
if pos("AUTOMATIC",scht) > 0 then do
nums = ''
numct= 0
closed = tcount
rndseed= tcount * rndcnt
do while closed ~= 0
t = random(1,closed,time('s'))
if find(nums,t) = 0 then do
if numct = 0 then do
numct = 1
nums = t
end
else do
numct = numct + 1
nums = nums||" "||t
end
end
if numct = tcount-1 then do
do f=1 to tcount
if pos(f,nums) = 0 then
nums = nums||" "f
end
numct = numct + 1
closed = 0
end
end
end
if open(outfile,league_file || input2_file,"w") then do
writeln(outfile,"*")
writeln(outfile,"**" cupname)
writeln(outfile,"*")
writeln(outfile,"*")
if pos("2 Legs",rnds.1) > 0 then
writeln(outfile,"*Round="word(rnds.1,1)" 1 Leg")
else
writeln(outfile,"*Round="word(rnds.1,1))
writeln(outfile,"*")
if pos("AUTOMATIC",scht) > 0 then do
home = 0
away = 0
do i=1 to tcount by 2
home = word(nums,i)
away = word(nums,i+1)
writech(outfile,left(teams.home,30))
writeln(outfile," __ __ " teams.away)
end
writech(outfile,"*")
end
close(outfile)
end
else do
say
say cs_error
say
say cs_t2"'"league_file || input2_file"'."
exit
end
matches = 0
left = tcount
do while left ~= 1
matches = matches + (left/2)
left = left / 2
end
if pos("YES",third) > 0 then
matches = matches + 1
do i=1 to rndcnt /* amend count if two legs */
if pos("2 Legs",rnds.i) > 0 then
matches = matches + 1
end
say
say center(cs_t8"'"cupname"'",78)
say "-------------------------------------------------------------------------------"
say " "cs_t9""date('e')""cs_t10""time()
say
say cs_t11""fversion
say "_______________________________________________________________________________"
say
say cs_t12""left(tcount,3)""cs_t14""matches
say " "cs_t15
say
if pos("MANUAL",scht) > 0 then
say cs_t16
else
say cs_t17
if pos("YES",third) > 0 then
say cs_t18
if pos("YES",cuph) > 0 then
say cs_t19
if pos("YES",awaygoals) > 0 then do
say cs_t20
say cs_t21
end
say
say "'"cupname"'"cs_t22""rndcnt""cs_t23
say cs_t24
say
say cs_t25
cs_line = ""
do cs_l=1 to length(cs_t25)+5
cs_line = cs_line||"-"
end
say cs_line
say
do i=1 to rndcnt
rndmsg = ""
if pos("1st",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t39)" "cs_t28,23)
if pos("2nd",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t40)" "cs_t28,23)
if pos("3rd",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t41)" "cs_t28,23)
if pos("4th",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t42)" "cs_t28,23)
if pos("5th",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t43)" "cs_t28,23)
if pos("Quart",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t35),23)
if pos("Semi",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t33),23)
if pos("Third",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t36),23)
if pos("Final",rnds.i) > 0 then rndmsg = rndmsg||left(strip(cs_t30),23)
if pos("No Ext.Time",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t3),19)
if pos("E.T If Rep.",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t4),19)
if pos("Extra Time",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t5),19)
if pos("No Pens.",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t6),21)
if pos("Pen If Rep.",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t7),21)
if pos("Penalties",rnds.i) > 0 then rndmsg = rndmsg||left(strip(fc_t8),21)
if pos("2 Legs",rnds.i) > 0 then rndmsg = rndmsg||fc_t2
say rndmsg
end
/*
if pos("1 Leg",rnds.i) > 0 then do
k = pos("1 Leg",rnds.i)
rnds.i = overlay(" ",rnds.i,k)
say rnds.i
end
else
say rnds.i
*/
say
say "_______________________________________________________________________________"
say
say cs_t26
say cs_t27
say
do i=1 to tcount
say teams.i
end
say
say "_______________________________________________________________________________"
say
if pos("2 Legs",rnds.1) > 0 then
say cs_t28": "bettername(word(rnds.1,1),"1 Leg")
else
say cs_t28": "bettername(word(rnds.1,1),cs_t29)
say "------------------------------------"
say
if pos("AUTOMATIC",scht) > 0 then do
home = 0
away = 0
do i=1 to tcount by 2
home = word(nums,i)
away = word(nums,i+1)
say left(teams.home,30)" __ __ "teams.away
end
say
say "-------------------------------------------------------------------------------"
say
end
exit
/* Routine ----------------------------------------------------------- */
bettername:
parse arg crn,legless
trdn = strip(substr(crn,1,1))
if datatype(trdn,'n') = 1 then do
parse var crn roundno" "extra
trn = strip(crn)" "cs_t28" "extra
end
else do
if pos(cs_t30,crn) > 0 then do
parse var crn . " "extra
if pos(cs_t31,crn) > 0 then
trn = cs_t30" "extra
else
trn = cs_t30
end
if pos(strip(cs_t45),crn) > 0 then do
parse var crn . " "extra
if pos(cs_t31,crn) > 0 then
trn = cs_t32" "extra
else
trn = cs_t33
end
if pos(strip(cs_t44),crn) > 0 then do
parse var crn . " "extra
if pos(cs_t31,crn) > 0 then
trn = cs_t34" "extra
else
trn = cs_t35
end
if pos(strip(cs_t46),crn) > 0 then do
trn = cs_t36
end
end
if pos("1 Leg",legless) > 0 then
trn = trn||" ("cum_t32")"
if pos("2 Legs",legless) > 0 then
trn = trn||" ("cum_t33")"
return trn
/* ------------------------------------------------------------------- */